package com.idione.activities;

import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ToggleButton;

import com.idione.util.LogUtil;
import com.idione.util.SoundSingleton;
import com.idione.util.VibSingleton;

public class Configuration extends Activity implements OnClickListener {

	private ToggleButton vibration, sound;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.configuration);

		/*-----------------------------------------------------------*
		 * Vibrator and sound    									 *
		 *-----------------------------------------------------------*/
		vibration = (ToggleButton) findViewById(R.id.TgBtnVibration);
		vibration.setChecked(VibSingleton.getInstance().vibratorIsActived());

		sound = (ToggleButton) findViewById(R.id.TgBtnSound);
		sound.setChecked(SoundSingleton.getInstance().soundIsActived());

		/*-----------------------------------------------------------*
		 * Listener     											 *
		 *-----------------------------------------------------------*/
		vibration.setOnClickListener(this);
		sound.setOnClickListener(this);

		Typeface tfb = LogUtil.getTypeFaceButton(this);
		vibration.setTypeface(tfb);
		sound.setTypeface(tfb);
	}

	@Override
	public synchronized void onClick(View call) {

		SoundSingleton.getInstance().PlaySoundClick();
		switch (call.getId()) {
		case R.id.TgBtnSound:
			if (sound.isChecked())
				SoundSingleton.getInstance().setSound(true);
			else
				SoundSingleton.getInstance().setSound(false);

			break;
		case R.id.TgBtnVibration:
			if (vibration.isChecked()) {
				VibSingleton.getInstance().setVibrator(true);
				VibSingleton.getInstance().Vip(this);
			} else
				VibSingleton.getInstance().setVibrator(false);

			break;
		}
	}

	@Override
	public void onBackPressed() {
		super.onBackPressed();
		overridePendingTransition(R.anim.push_up_in, R.anim.push_up_out);
	}
}
